<template>
	<view class="form-container safe-bottom-distance">
		<u-form :model="formData" label-width="200">
			<u-form-item label="身高(cm)">
				<u-input v-model="formData.height" clearable></u-input>
			</u-form-item>
			<u-form-item label="体重(公斤)">
				<u-input v-model="formData.weight" clearable></u-input>
			</u-form-item>
			<u-form-item label="腰围">
				<u-input v-model="formData.waist" clearable></u-input>
			</u-form-item>
			<u-form-item label="视力">
				<u-input v-model="formData.vision" clearable></u-input>
			</u-form-item>
			<u-form-item label="活动能力">
				<u-input v-model="formData.mobility" clearable></u-input>
			</u-form-item>
			<u-form-item label="血型">
				<u-input v-model="formData.blood" clearable></u-input>
			</u-form-item>
			<u-form-item label="过敏史">
				<u-input v-model="formData.allergies" clearable></u-input>
			</u-form-item>
			<u-form-item label="收缩压">
				<view class="flex-box">
					<view class="flex-max">
						<u-input v-model="formData.systolic" clearable/>
					</view>
					<navigator  class="nav-link" v-if="formData.systolic" url="./charts?type=4">
						<u-icon  name="eye"></u-icon>
					</navigator>
				</view>
			</u-form-item>
			<u-form-item label="舒张压">
				<view class="flex-box">
					<view class="flex-max">
						<u-input v-model="formData.diastolic" clearable/>
					</view>
					<navigator  class="nav-link" v-if="formData.diastolic" url="./charts?type=5">
						<u-icon  name="eye"></u-icon>
					</navigator>
				</view>
			</u-form-item>
			<u-form-item label="随机血糖情况">
				<view class="flex-box">
					<view class="flex-max">
						<u-input v-model="formData.bloodGlucose" clearable/>
					</view>
					<navigator  class="nav-link" v-if="formData.bloodGlucose" url="./charts?type=2">
						<u-icon  name="eye"></u-icon>
					</navigator>
				</view>
			</u-form-item>
			<u-form-item label="餐前血糖情况">
				<view class="flex-box">
					<view class="flex-max">
						<u-input v-model="formData.bloodGlucoseBeforeMeal" clearable/>
					</view>
					<navigator  class="nav-link" v-if="formData.bloodGlucoseBeforeMeal" url="./charts?type=0">
						<u-icon  name="eye"></u-icon>
					</navigator>
				</view>
			</u-form-item>
			<u-form-item label="餐后血糖情况">
				<view class="flex-box">
					<view class="flex-max">
						<u-input v-model="formData.bloodGlucoseAfterMeal" clearable/>
					</view>
					<navigator  class="nav-link" v-if="formData.bloodGlucoseAfterMeal" url="./charts?type=1">
						<u-icon  name="eye"></u-icon>
					</navigator>
				</view>
			</u-form-item>
			<u-form-item label="血脂情况">
				<u-input v-model="formData.bloodLipid" clearable></u-input>
			</u-form-item>
			<u-form-item label="血压情况">
				<view class="flex-box">
					<view class="flex-max">
						<u-input v-model="formData.bloodPressure" clearable/>
					</view>
					<navigator class="nav-link" v-if="formData.bloodPressure" url="./charts?type=6">
						<u-icon  name="eye"></u-icon>
					</navigator>
				</view>
			</u-form-item>
			<u-form-item label="脉搏数/分">
				<view class="flex-box">
					<view class="flex-max">
						<u-input v-model="formData.pulse" clearable/>
					</view>
					<navigator  class="nav-link"  v-if="formData.pulse" url="./charts?type=3">
						<u-icon  name="eye"></u-icon>
					</navigator>
				</view>
			</u-form-item>
			<u-form-item label="高血压">
				<u-radio-group v-model="formData.highBloodPressure">
					<u-radio :name="2">是</u-radio>
					<u-radio :name="1">否</u-radio>
				</u-radio-group>
			</u-form-item>
			<u-form-item label="高血糖">
				<u-radio-group v-model="formData.highBloodSuger">
					<u-radio :name="2">是</u-radio>
					<u-radio :name="1">否</u-radio>
				</u-radio-group>
			</u-form-item>
			<u-form-item label="高血脂">
				<u-radio-group v-model="formData.highBloodLipid">
					<u-radio :name="2">是</u-radio>
					<u-radio :name="1">否</u-radio>
				</u-radio-group>
			</u-form-item>
			<u-form-item label="耳背">
				<u-radio-group v-model="formData.hardHear">
					<u-radio :name="2">是</u-radio>
					<u-radio :name="1">否</u-radio>
				</u-radio-group>
			</u-form-item>
			<u-form-item label="骨质疏松">
				<u-radio-group v-model="formData.osteoporosis">
					<u-radio :name="2">是</u-radio>
					<u-radio :name="1">否</u-radio>
				</u-radio-group>
			</u-form-item>
			<u-form-item label="肺部疾病">
				<u-radio-group v-model="formData.copd">
					<u-radio :name="2">是</u-radio>
					<u-radio :name="1">否</u-radio>
				</u-radio-group>
			</u-form-item>
			<u-form-item label="冠心病">
				<u-radio-group v-model="formData.coronaryHeart">
					<u-radio :name="2">是</u-radio>
					<u-radio :name="1">否</u-radio>
				</u-radio-group>
			</u-form-item>
			<u-form-item label="脑卒中">
				<u-radio-group v-model="formData.stroke">
					<u-radio :name="2">是</u-radio>
					<u-radio :name="1">否</u-radio>
				</u-radio-group>
			</u-form-item>
			<u-form-item label="过敏史">
				<u-input v-model="formData.allergies" clearable></u-input>
			</u-form-item>
			<u-form-item label="肿瘤">
				<u-input v-model="formData.cancer" clearable></u-input>
			</u-form-item>
			<u-form-item label="残疾">
				<u-input v-model="formData.disability" clearable></u-input>
			</u-form-item>
			<u-form-item label="其他慢病">
				<u-input v-model="formData.otherDiseases" clearable></u-input>
			</u-form-item>
			<u-form-item label="其他病情">
				<u-input v-model="formData.others" clearable></u-input>
			</u-form-item>
			<u-form-item label="健康概述">
				<u-input v-model="formData.overview" clearable></u-input>
			</u-form-item>
		</u-form>
		<view class="submit-btn">
			<u-button type="success" @click="submit">提 交</u-button>
		</view>
	</view>
</template>

<script setup>
	import {ref,reactive} from "vue"
	import {onLoad,onReady} from "@dcloudio/uni-app"
	import {bindingBean} from "@/utils"
	import personnelApi from "@/api/personnel"
	const showModal = ref(false)
	const modalContent = ref("")
	const formData = reactive({
			  id:"",
		      userId:"",
		      height:"",
		      weight:"",
		      waist:"",
		      vision:"",
		      mobility:"",
		      blood:"",
		      allergies:"",
		      systolic:"",
		      coronaryHeart:"",
		      diastolic:"",

		      bloodGlucose:"",
		      bloodGlucoseBeforeMeal:"",
		      bloodGlucoseAfterMeal:"",
		      bloodLipid:"",
		      bloodPressure:"",
		      pulse:"",
		      otherDiseases:"",
		      coronaryHear:"",
		      stroke:"",
		      copd:"",
		      cancer:"",
		      overview:"",
		      highBloodPressure:"",
		      highBloodSuger:"",
		      highBloodLipid:"",
		      hardHear:"",
		      osteoporosis:"",
		      allergies:"",
		      disability:"",
		      others:"",
	})

	const submit = async ()=>{
		await uni.showModal({
			title:"提示",
			content:"确定提交"
		})
		if(formData.id){
		  await personnelApi.updateHealthRecentData(formData)
		}else{
		  await personnelApi.addHealthRecentData(formData)
		}
		uni.showToast({
			title:"提交成功",
			icon:"success"
		})
	}
	const getData = async ()=>{
		const {data} = await personnelApi.getHealthRecentData({userId:formData.userId})
		if(data) bindingBean(formData,data)
	}
	onLoad(({userId})=>{
		formData.userId = userId
		getData()
	})

</script>

<style lang="scss" scoped>
	.form-container {
		padding: 20rpx;
		.flex-box{
			display: flex;
			.nav-link{
				display: flex;
				align-items: center;
				:deep(.uicon-eye){
					font-size:55rpx !important;
					color: #b7b7b7;
				}
			}

			.flex-max{
				flex: 1;
			}
		}
		.submit-btn {
			width: 96vw;
			margin: 30rpx auto 20rpx;

		}
	}
</style>
